package asteroids.model.programs.parsing.expressions;

import java.util.List;
import java.util.Map;

import asteroids.model.Ship;
import asteroids.model.programs.parsing.types.*;

/**
 * A class of comparison expressions.
 * A comparison expression involves a single comparison operator applied to a left-hand operand and a right-hand operand.
 * 
 * @author Thijs Dieltjens - Wim Konings
 * @version 2.0
 */
public abstract class ComparisonExpr extends BinOpExpr {

	public ComparisonExpr(Expression e1, Expression e2,int line, int column) {
		super(e1, e2,line,column);
	}

	@Override
	public abstract BooleanLiteral eval(Ship ship, Map<String, Type> globals);

	@Override
	public  List<String> getTypeCheckErrors(List<String> errors, Map<String, Type> globals) {
		errors = getLeftOperand().getTypeCheckErrors(errors, globals);
		errors = getRightOperand().getTypeCheckErrors(errors, globals);

		try{
			if(!(getLeftOperand().eval(null, null) instanceof DoubleLiteral) || !(getRightOperand().eval(null, null) instanceof DoubleLiteral)){
				errors.add(getLine()+"-"+getColumn()+": This comparison must be between two doubles.");
			}	
		}
		catch(NullPointerException e){
			errors.add("No valid arguments for this comparison.");
		}
		return errors;
	}
}
